package com.label.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.label.Dao.ActivityApplyMapper;
import com.label.Model.Do.ActivityApply;
import com.label.Service.ActivityApplyService;
import com.label.Utils.UserUtil;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Component
@Transactional(rollbackFor = {Exception.class})
public class ActivityApplyServiceImpl extends ServiceImpl<ActivityApplyMapper,ActivityApply> implements ActivityApplyService {

    @Resource
    private ActivityApplyMapper activityApplyMapper;

    @Override
    public List<ActivityApply> getAllApply(){
        return activityApplyMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public ActivityApply getOneApply(String id){
        return activityApplyMapper.selectById(id);
    }

    @Override
    public List<ActivityApply> getApplyByUser(){
        return activityApplyMapper.selectList(new QueryWrapper<ActivityApply>().lambda().eq(ActivityApply::getUserid,UserUtil.getUserId()));
    }

    @Override
    public int addApply(ActivityApply activityApply){
        return activityApplyMapper.insert(activityApply);
    }

    @Override
    public int updateApply(ActivityApply activityApply){
        return activityApplyMapper.updateById(activityApply);
    }

    @Override
    public int delApply(String id){
        return activityApplyMapper.deleteById(id);
    }
}
